package com.kalvin.kvf.modules.xhs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.kalvin.kvf.common.controller.BaseController;
import com.kalvin.kvf.common.dto.R;
import com.kalvin.kvf.modules.xhs.entity.Cookie;
import com.kalvin.kvf.modules.xhs.service.XhsCookieService;

import java.util.List;


/**
 * <p>
 * 小红书登录信息的cookie 前端控制器
 * </p>
 * @since 2023-12-01 11:32:06
 */
@RestController
@RequestMapping("xhs/Cookie")
public class XhsCookieController extends BaseController {

    @Autowired
    private XhsCookieService CookieService;

    @RequiresPermissions("xhs:Cookie:index")
    @GetMapping("index")
    public ModelAndView index() {
        return new ModelAndView("xhs/Cookie");
    }

    @GetMapping(value = "edit")
    public ModelAndView edit(Long id) {
        ModelAndView mv = new ModelAndView("xhs/Cookie_edit");
        Cookie Cookie;
        if (id == null) {
            Cookie = new Cookie();
        } else {
            Cookie = CookieService.getById(id);
        }
        mv.addObject("editInfo", Cookie);
        return mv;
    }

    @GetMapping(value = "list/data")
    public R listData(Cookie Cookie) {
        Page<Cookie> page = CookieService.listCookiePage(Cookie);
        return R.ok(page);
    }

    @RequiresPermissions("xhs:Cookie:add")
    @PostMapping(value = "add")
    public R add(Cookie Cookie) {
        CookieService.save(Cookie);
        return R.ok();
    }

    @RequiresPermissions("xhs:Cookie:del")
    @PostMapping(value = "batchdel")
    public R batchdel(@RequestParam("ids") List<Long> ids) {
        CookieService.removeByIds(ids);
        return R.ok();
    }

    @RequiresPermissions("xhs:Cookie:edit")
    @PostMapping(value = "edit")
    public R edit(Cookie Cookie) {
        CookieService.updateById(Cookie);
        return R.ok();
    }

    @RequiresPermissions("xhs:Cookie:del")
    @PostMapping(value = "del/{id}")
    public R del(@PathVariable Long id) {
        CookieService.removeById(id);
        return R.ok();
    }

    @GetMapping(value = "get/{id}")
    public R get(@PathVariable Long id) {
        return R.ok(CookieService.getById(id));
    }

}

